﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using ModelLayer;
using Database;

namespace WCFServer
{
    public class DBCtrl : IDBCtrl
    {
        private NodesDB nodesDB;

        public DBCtrl()
        {
            nodesDB = new NodesDB();
        }

        public Node[] getNodes()
        {
            return nodesDB.getNodes().ToArray();
        }

        public Node getNodeById(int id)
        {
            return nodesDB.getNodeById(id);
        }

        public bool removeNode(int id)
        {
            return nodesDB.removeNode(id);
        }

        public bool updateNode(int id, string title, Coordinates coord, 
            ModelLayer.Type type, DateTime date)
        {
            Node node = new Node(title, id, date, type, coord);
            return nodesDB.updateNode(node);
        }

        public int addNode(string title, Coordinates coord,
            ModelLayer.Type type, DateTime date)
        {
            Node node = new Node(title, -1, date, type, coord);
            return nodesDB.insertNode(node);
        }
    }
}
